<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="public/static" /}
</head>
<body>

{include file="public/nav" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-table-body">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>数据库名称</th>
                                <th>卷数</th>
                                <th>压缩</th>
                                <th>数据大小</th>
                                <th>备份时间</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {volist name="info" id="data"}
                                <tr>
                                    <td>{$data.time|date='Ymd-His'}</td>
                                    <td>{$data.part}</td>
                                    <td>{$data.compress}</td>
                                    <td>{$data.size|formatBytes}</td>
                                    <td>{$key}</td>
                                    <td class="status">-</td>
                                    <td class="action">
                                        {eq name="check.Backupdown" value="1"}
                                            <a class="db-down" href="{:url('Backup/down',['time'=>$data['time']])}"><i class="layui-icon">&#xe601;</i> 下载</a>&nbsp;
                                        {/eq}
                                        {eq name="check.Backupimport" value="1"}
                                            <a class="db-import" href="{:url('Backup/import',['time'=>$data['time']])}"><i class="layui-icon">&#xe665;</i> 还原</a>&nbsp;
                                        {/eq}
                                        {eq name="check.Backupdel" value="1"}
                                            <a class="db-del" href="{:url('Backup/del',['time'=>$data['time']])}"><i class="layui-icon">&#xe640;</i> 删除</a>
                                        {/eq}
                                    </td>
                                </tr>
                            {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['jquery','layer'],function(){
        window.$ = layui.$;
        var layer = layui.layer;
        //数据还原
        $(".db-import").click(function(){
            var self = this, status = ".";
            layer.confirm('确定还原该数据吗？',function(index) {
                layer.close(index)
                //改变样式
                $(self).css({"pointer-events":"none", "color":"#bebebe"}).parent().prevAll('.status').html("").html('等待还原');
                //发送请求
                $.get(self.href, success, "json");
                //关闭提示
                window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
                return false;
                //成功回调方法
                function success(data){
                    if(data.status == 1){
                        $(self).parent().prev().html("<span style='color: #009688'>"+data.info+"</span>");
                        if(data.data){
                            $.get(self.href, {"part": data.data.part, "start": data.data.start},
                                success,
                                "json"
                            );
                        }else{
                            $(self).css({"pointer-events":"", "color":"#333"}) //恢复样式
                            layer.msg(data.info, {icon:6, time: 1500});
                            window.onbeforeunload = function(){ return null; }
                        }
                    } else {
                        layer.msg(data.info, {icon:5, time: 1500});
                    }
                }
            });
            return false;
        });
        //数据删除
        $(".db-del").click(function(){
            var self = this
            layer.confirm('确定删除该备份文件吗？',function() {
                var load = layer.load()
                $.ajax({
                    type:"post",
                    url: self.href,
                    dataType: 'json',
                    success:function (data) {
                        if(data.status === 1){
                            $(self).parent().parent().remove()
                            layer.msg(data.info, {icon: 6,time:1500});
                        }else{
                            layer.msg(data.info, {icon: 5,time:1500});
                        }
                        layer.close(load);
                    },
                    error:function (data) {
                        layer.msg("不好意思，出现了一点问题", {icon: 5});
                    }
                });
            })
            return false;
        })
    });
</script>
</html>